home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / edit_region.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  6.5 KB  |  284 lines

  1.  
  2. /*
  3.  *  edit_region.c            -Brian Tierney,   LBL
  4.  */
  5.  
  6. #include "ui.h"
  7. #include "common.h"
  8. #include "llist.h"
  9. #include "display.h"
  10. #include "reg.h"
  11. #include "log.h"
  12. #include "sm.h"
  13.  
  14. #define OFF 0
  15. #define EDIT 1
  16. #define DELETE 2
  17. #define COPY 3
  18. #define FRAME_COPY 4
  19. #define HIDE 5
  20.  
  21. static int curr_edit_func = OFF;
  22. static int edit_log_id = 0;
  23.  
  24. void      edit_log_num_proc();
  25. struct logent *log_by_id();
  26.  
  27. #define DEBUG
  28.  
  29. void
  30. edit_region_proc(item, value, event)
  31.     Panel_item item;
  32.     int       value;
  33.     Event    *event;
  34. {
  35.     fprintf(stderr, "in edit_region_proc: val = %d \n", value);
  36.  
  37.     curr_edit_func = value;
  38.  
  39.     /* make sure that there is at least 1 logged item */
  40.     if (loghead == NULL || loghead->next == NULL) {
  41.     xv_set(base_win->edit_mode, PANEL_VALUE, 0, NULL);
  42.     value = 0;
  43.     }
  44.     clear_info();
  45.     switch (value) {
  46.     case 0:
  47. #ifdef DEBUG
  48.     fputs("genial: edit_region: off\n", stderr);
  49. #endif
  50.     xv_set(base_win->edit_log_num, PANEL_INACTIVE, TRUE, NULL);
  51.     xv_set(base_win->edit_ok, PANEL_INACTIVE, TRUE, NULL);
  52.  
  53.     /* reset to previous state */
  54.     if ((curfunc = log_by_id(get_current_lid())) == NULL)
  55.         return;
  56.  
  57.     set_plist_globals(curfunc->reg);
  58.  
  59.     fxn_select(curfunc->opcode);
  60.     xv_set(base_win->func_sel, PANEL_VALUE, curfunc->opcode, NULL);
  61.     xv_set(base_win->message9, PANEL_LABEL_STRING, "   ", NULL);
  62.     fxn_init();
  63.     new_state(IMG_LOADED);
  64.     break;
  65.  
  66.     case 1:
  67.     lab_info("move points with left mouse button", 1);
  68.     lab_info("Hit <eval> when done moving points", 2);
  69.     lab_info("reset edit-mode to Off to select next region", 3);
  70.  
  71.     edit_setup(loghead->id);
  72.     break;
  73.  
  74.     case 2:            /* delete */
  75.     lab_info("select object to delete by log number", 1);
  76.     lab_info("Hit <OK> when done", 2);
  77.     lab_info("reset edit-mode to Off to select next region", 3);
  78.  
  79.     edit_setup(loghead->id);/* wait till OK button is pushed before doing
  80.                  * anything */
  81.     break;
  82.  
  83.     case 3:
  84.     lab_info("not yet implemented", 1);
  85.     lab_info("reset edit-mode to Off to select next region", 3);
  86.  
  87.     fputs("genial: edit_region: copy (not yet implemented)\n", stderr);
  88.     edit_setup(loghead->id);
  89.     break;
  90.     case 4:
  91.     lab_info("not yet implemented", 1);
  92.     lab_info("reset edit-mode to Off to select next region", 3);
  93.  
  94.     fputs("genial: edit_region: frame copy (not yet implemented)\n", stderr);
  95.     edit_setup(loghead->id);
  96.     break;
  97.     case 5:
  98.     lab_info("not yet implemented", 1);
  99.     lab_info("reset edit-mode to Off to select next region", 3);
  100.  
  101.     fputs("genial: edit_region: hide (not yet implemented)\n", stderr);
  102.     edit_setup(loghead->id);
  103.     break;
  104.     }
  105. }
  106.  
  107. /***************************************************************/
  108. edit_setup(id)
  109.     int       id;
  110. {
  111.     fprintf(stderr, "in edit setup: id = %d \n", id);
  112.  
  113.     new_state(REG_EDIT);
  114.  
  115.     xv_set(base_win->edit_ok, PANEL_INACTIVE, FALSE, NULL);
  116.     xv_set(base_win->edit_log_num, PANEL_INACTIVE, FALSE, NULL);
  117.  
  118.     /* set default log item */
  119.     xv_set(base_win->edit_log_num, PANEL_VALUE, 0, NULL);
  120.     edit_log_num_proc(NULL, 0, NULL);
  121.  
  122.     set_log_num_choices();
  123. }
  124.  
  125. /***************************************************************/
  126. /*
  127.  * Notify callback function for `edit_log_num'.
  128.   */
  129. void
  130. edit_log_num_proc(item, value, event)
  131.     Panel_item item;
  132.     int       value;
  133.     Event    *event;
  134. {
  135.     struct logent *func;
  136.  
  137. #ifdef DEBUG
  138.     fprintf(stderr, "edit setup: value %d \n", value);
  139. #endif
  140.  
  141.     edit_log_id = atoi((char *) xv_get(base_win->edit_log_num,
  142.                        PANEL_CHOICE_STRING, value, NULL));
  143. #ifdef DEBUG
  144.     fprintf(stderr, "editting log id # %d \n", edit_log_id);
  145. #endif
  146.  
  147.     if ((func = log_by_id(edit_log_id)) == NULL) {
  148.     fprintf(stderr, "Log Number not found \n");
  149.     XBell(display, 0);
  150.     return;
  151.     }
  152.     curfunc = func;
  153.     set_plist_globals(curfunc->reg);
  154.     fxn_select(curfunc->opcode);
  155.     xv_set(base_win->func_sel, PANEL_VALUE, curfunc->opcode, NULL);
  156.     xv_set(base_win->message9, PANEL_LABEL_STRING,
  157.        func_names[curfunc->opcode], NULL);
  158. }
  159.  
  160. /***************************************************************/
  161. set_log_num_choices()
  162. {
  163.     int       i = 0, log_cnt = 0;
  164.     char    **log_id_buf, **alloc_2d_char_array();
  165.     struct logent *func;
  166.  
  167.     /* first count the number of entries */
  168.     func = loghead;
  169.     while (func->next != NULL) {
  170.     log_cnt++;
  171.     func = func->next;
  172.     }
  173.  
  174.     if (log_cnt <= 0)
  175.     return;
  176.  
  177.     log_id_buf = alloc_2d_char_array(log_cnt, 4);
  178.     func = loghead;
  179.     while (func->next != NULL) {
  180.     sprintf(log_id_buf[i], "%d", func->id);
  181.     func = func->next;
  182.     i++;
  183.     }
  184.  
  185. #ifdef DEBUG
  186.     printf(" setting number of log item choices: %d \n", log_cnt);
  187. #endif
  188.  
  189.     xv_set(base_win->edit_log_num, PANEL_CHOICE_STRINGS, "1", NULL, NULL);
  190.  
  191.     for (i = 0; i < log_cnt; i++)
  192.     xv_set(base_win->edit_log_num,
  193.            PANEL_CHOICE_STRING, i, log_id_buf[i], NULL);
  194.  
  195.     free(log_id_buf);
  196. }
  197.  
  198. /***************************************************************/
  199. void
  200. do_edit_proc()
  201. {                /* edit OK button pushed */
  202.  
  203.     if (curfunc == NULL)
  204.     return;
  205.  
  206.     if (curr_edit_func == EDIT) {
  207.     do_edit_eval();        /* same as eval button */
  208.     }
  209.     if (curr_edit_func == DELETE) {
  210.     fxn_clear(curfunc);
  211.     log_del(edit_log_id);
  212.     set_log_num_choices();
  213.     edit_region_proc(NULL, 2, NULL);    /* reset stuff */
  214.     }
  215. }
  216.  
  217. #ifdef NEED_LATER
  218. /***************************************************************/
  219. /* pfind_all() -- search all regions for an entry in a plist
  220.  *  within 20 pixels' distance from the  given point
  221.  */
  222.  
  223. struct plist
  224.          *
  225. pfind_all(dpt)
  226.     XPoint    dpt;
  227. {
  228.     int       sm = 20;
  229.     int       dist;
  230.     struct plist *trp;
  231.     struct logent *cfunc;
  232.     struct plist *list_head;
  233.  
  234.     cfunc = logtail;
  235.     while (cfunc) {
  236.     list_head = cfunc->reg->r_plist[0];
  237.  
  238.     for (trp = list_head; trp != NULL; trp = trp->next) {
  239.         dist = (int) irint(distance(trp->pt, dpt));
  240. #ifdef DEBUG
  241.         printf("distance to point:%d\n", dist);
  242. #endif
  243.         if (dist <= sm) {
  244.         curfunc = cfunc;/* set global curfunc pointer */
  245.         setnpoints(curfunc->reg->r_plen + 1);
  246.         cplhead = curfunc->reg->r_plist[0];
  247.         setpvreg(curfunc->reg);
  248.         return trp;
  249.         }
  250.     }
  251.     cfunc = cfunc->prev;
  252.     }
  253.     return NULL;
  254. }
  255.  
  256.  
  257. #endif
  258.  
  259. /**********************************/
  260. char    **
  261. alloc_2d_char_array(nx, ny)
  262.     int       nx, ny;
  263. {
  264.     char    **array;
  265.     register int i;
  266.  
  267. #define Calloc(x,y) (y *)calloc((unsigned)(x), sizeof(y))
  268.  
  269.     /* allocate 2-d array for input image data */
  270.     /* allocate array of pointers */
  271.     if ((array = Calloc(nx, char *)) == NULL)
  272.     perror("calloc error: array ");
  273.  
  274.     /* allocate array for data */
  275.     if ((array[0] = Calloc(nx * ny, char)) == NULL)
  276.     perror("calloc error: array ");
  277.  
  278.     /* initialize pointer arrays */
  279.     for (i = 1; i < nx; i++)
  280.     array[i] = array[0] + (ny * i);
  281.  
  282.     return (array);
  283. }
  284.